<?php
class stflickr_set_photo_model extends stmodel_2_1{

    public function __construct($config) {
        parent::__construct ( $config );
        $this->setTableName($this->prefix.'st_flickr_set_photo');
        $this->setPrimaryKey('id');
    }

    public function saveStflickrSetPhoto($set_id, $photos) {
        foreach ($photos as $photo) {
            $data[$i]['id'] = 'NULL';
            $data[$i]['photo_id'] = $photo['id'];
            $data[$i]['set_id'] = $set_id;
            $i++;
        }
        if(!empty($data)){
            $this->inserRecords($data);
        }
        //var_dump($data);
    }

    
    public function inserRecords($data = '', $where = ''){
        if(count($data)>0){
            $query = "INSERT INTO $this->_tableName
                    ( id, photo_id, set_id )
                    VALUES
                    ";
            $query1 = array();
            foreach ($data as $value) {
                $query1[] = $this->prepare("(%d, %s, %s)",
                        $value['id'], $value['photo_id'], $value['set_id']
                        );
            }
            $query1 = implode(', ', $query1);
            $query .= ' '.$query1;
//            echo $query;
            return $this->query( $query );
        }else{
            return false;
        }
    }

    public function emptyTable(){
        $query = "TRUNCATE TABLE `$this->_tableName`";
        $result = $this->get_var($query);
        return $result;
    }

}